package com.wgts.wgts.mvp.view.activity.myorder;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.netmodle.resp.EvaluateEntity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 *
 *
 *   data:2018/9/2516:46
 *
 */public class EvaluateMeassageAdapter extends RecyclerView.Adapter<EvaluateMeassageAdapter.ViewHold> {
    private Context context;
    private List<EvaluateEntity.Evaluate> list;
    private onItemClickListen onItemClickListen;

    public EvaluateMeassageAdapter(Context context, List<EvaluateEntity.Evaluate> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate
                (R.layout.evaluate_meassage_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHold viewHold, int i) {
        viewHold.evaluateMeassageText.setText(list.get(i).msg);
        if (list.get(i).isSelect){
            viewHold.evaluateMeassageImage.setSelected(true);
            viewHold.evaluateMeassageText.setTextColor(ContextCompat.getColor(context, R.color.black));
        }else {
            viewHold.evaluateMeassageImage.setSelected(false);
            viewHold.evaluateMeassageText.setTextColor(ContextCompat.getColor(context, R.color.logistics_text));
        }
        if (onItemClickListen != null){
            viewHold.evaluateMeassageLy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int position = viewHold.getLayoutPosition();
                    onItemClickListen.onItemClick(viewHold.evaluateMeassageLy, position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.evaluate_meassage_image)
        ImageView evaluateMeassageImage;
        @BindView(R.id.evaluate_meassage_text)
        TextView evaluateMeassageText;
        @BindView(R.id.evaluate_meassage_ly)
        LinearLayout evaluateMeassageLy;
        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
    public void setOnItemClickListen(onItemClickListen onItemClickListen){
        this.onItemClickListen = onItemClickListen;
    }
    public interface onItemClickListen{
        void onItemClick(View view, int position);
    }

}
